<!--
 * @description 页面介绍
 * @author dumeng
 * @date 2021/9/22
 -->
<template>
  <div class="group-members-page">
    <el-collapse-transition>
      <div v-show="searchshow" class="common-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model.trim="listQuery.commonParam"
          placeholder="请输入关键字搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <div class="common-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="common-search separate">
        <div class="common-search-inner">
          <el-row>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">真实姓名</div>
                <el-input
                  v-model.trim="search.userRealName"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入真实姓名搜索"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">联系电话</div>
                <el-input
                  v-model.trim="search.userPhone"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入联系电话搜索"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">证件号</div>
                <el-input
                  v-model.trim="search.userIdnumber"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入完整证件号"
                />
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="common-search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <div class="btn-container">
      <div class="btn-container-title">
        <span>小组成员</span>
      </div>
      <div class="btn-container-btns">
        <el-button style="margin-left: 10px" @click="handleExport">导出人员</el-button>
      </div>
    </div>
    <div class="table">
      <el-table
        v-loading="listLoading"
        :data="list"
        class="tableScope"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="userRealName" label="姓名" show-overflow-tooltip width="130" />
        <el-table-column prop="userSex" label="性别" show-overflow-tooltip width="130">
          <template slot-scope="scope">
            <span>{{ scope.row.userSex==='MAN'?'男':'女' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="userPhone" label="手机号码" show-overflow-tooltip width="130">
          <template slot-scope="scope">
            <span>{{ handleDecrypt(scope.row.userPhone) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="userIdnumber" label="证件号" width="200" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ handleDecrypt(scope.row.userIdnumber) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="deptName" label="所属部门" show-overflow-tooltip />
      </el-table>
    </div>
    <div class="btn-pagion fix">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>

import CryptoJS from '@/utils/aesJiaJM'
import { queryUser, exportUserMask, exportUserNoMask } from '@/views/staffserve/interestGroup/api/groupManage'
import { exportSign } from '@/utils/fileImportOrExportSign'
import Pagination from '@/components/Pagination'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
export default {
  name: 'GroupMembers',
  components: { Pagination },
  props: {
    groupId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 10,
        commonParam: '',
        isSearch: 0
      },
      list: [],
      total: 0,
      searchshow: true,
      search: {
        userRealName: '',
        userPhone: '',
        userIdnumber: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /**
     * 解密
     */
    handleDecrypt(str) {
      return CryptoJS.$aesJieM(str)
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        groupId: this.groupId || '',
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      if (this.searchshow) {
        query['commonParam'] = this.listQuery.commonParam
      } else {
        query['userRealName'] = this.search.userRealName
        query['userPhone'] = this.search.userPhone
        query['userIdnumber'] = this.search.userIdnumber
      }
      return new Promise((resolve, reject) => {
        queryUser(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.commonParam = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.listQuery.page = 1
      this.getList()
    },
    /**
     * 导出人员
     */
    handleExport() {
      const query = {
        groupId: this.groupId || ''
      }
      if (this.searchshow) {
        query['commonParam'] = this.listQuery.commonParam
      } else {
        query['userRealName'] = this.search.userRealName
        query['userPhone'] = this.search.userPhone
        query['userIdnumber'] = this.search.userIdnumber
      }
      for (const i in query) {
        if (query[i] === '') {
          delete query[i]
        }
      }
      exportCheck('STAFF_SERVICE_INTERESTGROUP', this.groupId, exportUserMask, exportUserNoMask, exportSign(query).obj, '人员信息.xlsx')
    }

  }
}
</script>

<style scoped lang="scss">
.group-members-page{
  background-color: #ffffff;
  height: 100%;
  padding: 10px;
  padding-top: 0;
  overflow-y: auto;
  min-height: calc(100vh - 140px);
  &::-webkit-scrollbar {
    display: none;
  }

  .common-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 10px;
      }
    }

    .search-input {
      width: 40%;
      position: relative;
      //
      //&:after {
      //  content: '';
      //  position: absolute;
      //  left: -25px;
      //  right: 0;
      //  bottom: 8px;
      //  height: 1px;
      //  background: rgba(226, 227, 232, 1);
      //}

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .common-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .common-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .common-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-checkbox__label {
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .common-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .btn-container {
    display: flex;
    height: 36px;
    line-height: 36px;
    margin-top: 15px;
    margin-bottom: 15px;

    .btn-container-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      color: rgba(51, 51, 51, 1);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      .btn-container-title-select {
        @include font-color($mainColor);
      }
    }
  }

  .el-table {
    height: calc(100% - 40px);
    overflow-y: auto;

    &::-webkit-scrollbar {
      display: none;
    }
  }

  .dataForm {
    .el-select {
      width: 100%;
    }
  }

  .upload-model {
    text-align: center;
  }
  .image-preview .el-dialog__body {
    text-align: center;
    .image-box {
      width: 200px;
      height: 80px;
      border: 2px dashed #ff9f91;
      border-radius: 5px;
    }
  }

}
</style>
